package com.example.cloud.service.system.impl;

import com.example.cloud.dao.system.AnnounceRepository;
import com.example.cloud.model.system.Announce;
import com.example.cloud.model.system.User;
import com.example.cloud.service.system.AnnounceService;
import com.example.cloud.utils.BusinessUtil;
import com.example.cloud.utils.RequestUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * Created by wangtao on 2018/2/3.
 */
@Service
public class AnnounceServiceImpl implements AnnounceService {

    private static final Logger logger = Logger.getLogger(AnnounceServiceImpl.class);

    @Autowired
    private AnnounceRepository announceRepository;

    @Override
    public Announce findOne() {
        User loginUser = RequestUtil.getLoginUser();
        return announceRepository.findByAccountIdAndOrganId(loginUser.getAccountId(), loginUser.getOrganId());
    }

    @Override
    @Transactional
    public void doSave(Announce record) {
        User loginUser = RequestUtil.getLoginUser();
        record.setAccountId(loginUser.getAccountId());
        record.setOrganId(loginUser.getOrganId());
        record.setOrganName(loginUser.getOrganName());
        BusinessUtil.appendRecord(record);
        announceRepository.save(record);
    }
}
